home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 23 / AACD 23.iso / AACD / Online / opennap / muzzle.c < prev    next >
C/C++ Source or Header  |  2001-06-08  |  3KB  |  142 lines

  1. /* Copyright (C) 2000-1 drscholl@users.sourceforge.net
  2.    This is free software distributed under the terms of the
  3.    GNU Public License.  See the file COPYING for details.
  4.  
  5.    $Id: muzzle.c,v 1.36 2001/02/15 08:39:45 drscholl Exp $ */
  6.  
  7. #include <string.h>
  8. #include <stdio.h>
  9. #include <stdlib.h>
  10. #include "opennap.h"
  11. #include "debug.h"
  12.  
  13. /* [ :<sender> ] <target-user> [ "<reason>" ]
  14.    muzzle/unmuzzle a user */
  15. HANDLER (muzzle)
  16. {
  17.     USER   *user, *sender;
  18.     char   *av[2], *sender_name;
  19.     int     ac = -1;
  20.     USERDB *db;
  21.     int     curlevel;
  22.     int     denied = 0;
  23.  
  24.     (void) len;
  25.     ASSERT (validate_connection (con));
  26.  
  27.     if (pop_user_server (con, tag, &pkt, &sender_name, &sender))
  28.     return;
  29.  
  30.     if (pkt)
  31.     ac = split_line (av, FIELDS (av), pkt);
  32.  
  33.     if (ac < 1)
  34.     {
  35.     unparsable (con);
  36.     return;
  37.     }
  38.  
  39.     /* find the user to be muzzled.  user may not be currently logged in. */
  40.     user = hash_lookup (Users, av[0]);
  41.  
  42.     /* look up this entry in the user db.  may not be registered. */
  43.     db = hash_lookup (User_Db, av[0]);
  44.  
  45.     /* check for permission to execute */
  46.     if (sender)
  47.     {
  48.     /* non-mods are never allowed to muzzle */
  49.     if (sender->level < LEVEL_MODERATOR)
  50.     {
  51.         denied = 1;
  52.     }
  53.     /* if not Elite, allow muzzling users of lower levels */
  54.     else if (sender->level < LEVEL_ELITE && (user || db))
  55.     {
  56.         curlevel = db ? db->level : user->level;
  57.         if (sender->level <= curlevel)
  58.         {
  59.         denied = 1;
  60.         }
  61.     }
  62.  
  63.     if (denied)
  64.     {
  65.         send_user (sender, MSG_SERVER_NOSUCH,
  66.                "[%s] %smuzzle failed: permission denied",
  67.                Server_Name, (tag == MSG_CLIENT_UNMUZZLE) ? "un" : "");
  68.         if (ISSERVER (con))
  69.         {
  70.         /* fix desync */
  71.         log ("muzzle: %s is desynced", con->host);
  72.         send_cmd (con,
  73.               (tag ==
  74.                MSG_CLIENT_MUZZLE) ? MSG_CLIENT_UNMUZZLE :
  75.               MSG_CLIENT_MUZZLE, ":%s %s \"%s is desynced\"",
  76.               Server_Name, av[0], con->host);
  77.         }
  78.         return;
  79.     }
  80.     }
  81.  
  82.     if (!db)
  83.     {
  84.     if (user)
  85.         db = create_db (user);
  86.     }
  87.  
  88.     if (ac > 1)
  89.     truncate_reason (av[1]);
  90.  
  91.     if (db)
  92.     {
  93.     if (tag == MSG_CLIENT_MUZZLE)
  94.     {
  95.         if (db->flags & ON_MUZZLED)
  96.         return;        /* already set */
  97.         db->flags |= ON_MUZZLED;
  98.     }
  99.     else
  100.     {
  101.         if (!(db->flags & ON_MUZZLED))
  102.         return;        /* already unset */
  103.         db->flags &= ~ON_MUZZLED;
  104.     }
  105.  
  106.     if (user)
  107.     {
  108.         if (tag == MSG_CLIENT_MUZZLE)
  109.         user->muzzled = 1;
  110.         else
  111.         user->muzzled = 0;
  112.  
  113.         if (ISUSER (user->con))
  114.         {
  115.         char   *who;
  116.  
  117.         if (sender && sender->cloaked
  118.             && user->level < LEVEL_MODERATOR)
  119.             who = "Operator";
  120.         else
  121.             who = sender->nick;
  122.  
  123.         send_cmd (user->con, MSG_SERVER_NOSUCH,
  124.               "You have been %smuzzled by %s%s: %s",
  125.               user->muzzled ? "" : "un",
  126.               !sender ? "Server " : "",
  127.               sender_name, (ac > 1) ? av[1] : "");
  128.         }
  129.     }
  130.     }
  131.  
  132.     /* relay to peer servers */
  133.     pass_message_args (con, tag, ":%s %s \"%s\"", sender_name, av[0],
  134.                (ac > 1) ? av[1] : "");
  135.  
  136.     /* notify mods+ of this action */
  137.     notify_mods (MUZZLELOG_MODE, "%s%s has %smuzzled %s: %s",
  138.          !sender ? "Server " : "",
  139.          sender_name, (tag == MSG_CLIENT_MUZZLE) ? "" : "un",
  140.          av[0], (ac > 1) ? av[1] : "");
  141. }
  142.